<script type="text/javascript">
function showCalendar(obj){
	$(obj).datepicker();
}




function displaySearchDialog()
{
		$( "#displaySearchDialog" ).dialog({
			height: 225,
			width: 700,
			modal: true,
			buttons: [{
			text: "Search",
			click: function() {
			$("#searchTransactionForm").submit(); }
			},{
			text: "Close",
			click: function() { $(this).dialog("close"); }
			}]
		});

}





$(document).ready(function(){
	$("#onboarddate\\*").datepicker();
	$("#dateofpickup\\*").datepicker();

//	$("#dateofdelivered").datepicker();
});

function displayDownloadDialog()
{
		$( "#displayDownloadDialog" ).dialog({
			height: 225,
			width: 700,
			modal: true,
			buttons: [{
			text: "Download",
			click: function() {
			$("#downloadTransactionForm").submit(); }
			},{
			text: "Close",
			click: function() { $(this).dialog("close"); }
			}]
		});

}


</script>
<!-- Container -->
<div id="container">
	<div class="shell">

		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a> <span>&gt;</span> Current Transactions
		</div>
		<?php
		$label = 'transaction';
		include 'includes/message.php';
		?>
		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>

			<!-- Content -->
			<div id="content">

			<?php
			//echo (!isset($page))."----------------------------------------------".($page == '');
			if($action == ''){
				?>

				<!-- Box -->
				<div class="box" style="width: 1000px">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">
							Current Transaction
							<h2>
								<div class="right">
									<input type="submit" class="button" value="search transaction"
										onclick="displaySearchDialog()" /> <input type="submit"
										class="button" value="Transaction Report"
										onclick="displayDownloadDialog()" />


								</div>
					
					</div>
					<!-- End Box Head -->

					<!-- Table -->
					<div class="table" style="width: 100%">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>

								<th>Client Name</th>
								<th>Track Number</th>
								<th>DR Number</th>
								<th>Commodity</th>
								<th>Pick up Address</th>
								<th>Destination<br>Point</th>
								<th>On Board<br>Date</th>
								<th width="110" class="ac">Action</th>
							</tr>

							<?php
							//transactionList
							if(isset($transactionList) && $transactionList->num_rows()>0)
							foreach ($transactionList->result() as $transaction)
							{
								
							 $_commodity = $transaction->commodity;
							 $_pickupaddress = $transaction->pickupaddress;
							 $_deliverypoint = $transaction->deliverypoint;
							
							if(strlen($_commodity) > 20)
								$_commodity =  substr($_commodity , 0, 20)."...";
							
							
							if(strlen($_pickupaddress) > 20)
								$_pickupaddress =  substr($_pickupaddress , 0, 20)."...";
							
							
							if(strlen($_deliverypoint) > 20)
								$_deliverypoint =  substr($_deliverypoint , 0, 20)."...";
		
								echo "<tr>
											<td>".$transaction->clientname."</td>
											<td>".$transaction->referencenumber."</td>
											<td>".$transaction->dr_number."</td>
											<td>".$_commodity."</td>
											<td>".$_pickupaddress."</td>
											<td>".$_deliverypoint."</td>
											<td>".$transaction->onboarddate."</td>
											<td><a href='".ADMINBASEURL."$label/edit/".$transaction->trans_id."'  class='ico edit'>edit</a>
											&nbsp;<a href='".ADMINBASEURL."$label/delete/".$transaction->trans_id."'  class='ico del'>delete</a></td>
										</tr>";


							}
							?>

						</table>

						<?php
						include 'includes/pagination.php';
						?>

					</div>
					<!-- Table -->

				</div>
				<!-- End Box -->



				<?php
			}else if($action == 'add'){
				?>

				<!-- Content -->
				<!-- Box -->
				<div class="box" style="width: 1000px">

					<!-- End Box Head-->
					<div class="box-head">
						<h2>Search Client Record</h2>
					</div>
					<div class="box-content">
						<form action="<?php echo ADMINBASEURL."$label/add/"; ?>"
							method="post">
							<div class="form">
								<table style="width: 80%" class="table">
									<tr>
										<td><label>First Name</label>
										</td>
										<td><label> <span><input type="text" name='firstname'
													class="field size4"
													value="<?php echo (isset($firstname))?$firstname:'';?>"> </span>
										</label>
										</td>
										<td><label>Middle Name</label>
										</td>
										<td><label> <span><input type="text" name='middlename'
													class="field size4"
													value="<?php echo (isset($middlename))?$middlename:'';?>">
											</span> </label>
										</td>
										<td><label>Last Name:</label>
										</td>
										<td colspan="3"><label> <span><input type="text"
													name='lastname' class="field size4"
													value="<?php echo (isset($lastname))?$lastname:'';?>"> </span>
										</label>
										</td>
									</tr>

									<tr>
										<td><label>Client Track #:</label>
										</td>
										<td><label> <span><input type="text" name='clientTrackNum'
													class="field size4"
													value="<?php echo (isset($clientTrackNum))?$clientTrackNum:'';?>">
											</span> </label>
										</td>
										<td align="right" colspan="3"><label><input type="submit"
												name="searchByClient" class="button" value="Search Client">
										</label>
										</td>
									</tr>
								</table>
							</div>
						</form>

						<?php
						if (isset($searchedClients) && $searchedClients->num_rows() > 0)
						{
							?>

						<div class="box" style="width: 100%">
							<div class="box-head">
								<h2 class="left">Results</h2>
							</div>
							<!-- Table -->
							<div class="table" style="width: 100%">
								<table width="100%" border="0" cellspacing="0" cellpadding="0">

								<?php
								echo "<tr>
											<th>Client Name</th>
											<th>Username</th>
											<th>Client Reference #</th>
											<th>Email</th>
											<th>Acion</th>
											</tr>";
								foreach ($searchedClients->result() as $user)
								{
									echo "<tr>
														<td>".$user->firstname." ".$user->middlename." ".$user->lastname."</td>
														<td>".$user->username."</td>
														<td>".$user->referencenumber."</td>
														<td>".$user->email."</td>
														<td><a href='".ADMINBASEURL."$label/create/".$user->id."'>add Transaction</a></td>
													</tr>";


								}
								?>

								</table>
							</div>
						</div>
						<?php
						}
						?>
						<div class="cl">&nbsp;</div>
					</div>
				</div>

				<?php
			}else{
				?>

				<!-- Box -->
				<div class="box" style="width: 1000px">
					<!-- Box Head -->
					<div class="box-head">
						<h2>Add New Transaction</h2>
					</div>
					<!-- End Box Head -->

					<form action="<?php echo ADMINBASEURL."$label/save/";?>"
						onsubmit="return MyForm.validate(this);" method="post">

						<!-- Form
Full Name	Username	Email	Usertype	Warehouse	Created By
						-->
						<div class="form">

							<table width="200" border="0">
								<tr>
									<td><label>Client Information:</label></td>
								</tr>
							</table>


							<div class="form">
								<table class="table">
								<?php
								if(isset($client)){
									?>
									<tr>
										<td><input type="hidden" name="clientid"
											value="<?php echo $client->id ?>"> <label>Client Name:<?php echo $client->firstname." ".$client->middlename." ".$client->lastname?>
										</label>
										</td>
										<td width="21%"><label>Client Track #: <span><?php echo $client->referencenumber;?>
											</span> </label>
										</td>
										<?php
								}if(isset($transactionDetails)){
									?>
										<td width="23%"><input type="hidden" name="id"
											value="<?php echo $transactionDetails->trans_id; ?>"> <input
											type="hidden" name="clientid"
											value="<?php echo $transactionDetails->clientid; ?>"> <label>Client
												Name: <span><?php echo $transactionDetails->clientname; ?> </span>
										</label>
										</td>
										<td width="23%"><label>Client Track #: <span><?php echo $transactionDetails->referencenumber;?>
											</span> </label>
										</td>

										<?php
								}
								?>
									</tr>
								</table>
								<br>
							</div>




							<table width="200" border="0">
								<tr>
									<td height="39"><label>Transaction Details:</label></td>
								</tr>
							</table>


							<div class="table">
								<table width="100%" cellpadding="0" cellspacing="0">
								<?php
								if(isset($transactionDetails)){
									?>
									<tr>
										<td width="64%" valign="top" style="text-align: top"><span
											class="req"></span> <label>DR Number <span></span> </label> <input
											type="text" name="dr_number" class="field size1"
											style="width: 200px; text-align: center" readonly
											value="<?php echo isset($transactionDetails)?$transactionDetails->dr_number:'';?>" /><br>

										</td>
										<td width="33%" valign="top" style="text-align: top"><span
											class="req"></span> <label>Status<span></span> </label> <select
											class="field size3" name="status">
												<option value='NEW'
												<?php echo (isset($transactionDetails) && $transactionDetails->status == 'NEW')?'SELECTED':'';?>>
													NEW</option>
												<option value='PENDING'
												<?php echo (isset($transactionDetails) && $transactionDetails->status == 'PENDING')?'SELECTED':'';?>>PENDING</option>
												<option value='DELIVERED'
												<?php echo (isset($transactionDetails) && $transactionDetails->status == 'DELIIVERED')?'SELECTED':'';?>>DELIVERED
												</option>

										</select><br>
										</td>
									</tr>
									<?php
								}
								?>
									<tr>
										<td height="70" valign="top" style="text-align: top"><span
											class="req"></span> <label>Commodity <span></span> </label> <textarea
												class="field size3" rows="5" style="width: 90%"
												name="commodity" id="commodity*" alt="Commodity">
												<?php echo isset($transactionDetails)?$transactionDetails->commodity:'';?>
											</textarea>
										</td>



										<td valign="top" style="text-align: top"><span class="req"></span>
											<label style="text-align: left">Volume<span></span> </label>
											<table>
												<tr>
													<th>No. of<br>Packages</th>
													<th>Volume</th>
													<th>Quantity</th>
													<th>Sizes of<br>Container</th>
												</tr>
												<tr>
													<td><input type="text" class="field size1"
														alt="Volume Quantity"
														style="width: 50px; text-align: center"
														id="volume_packages*" name="volume_packages"
														value="<?php echo isset($transactionDetails)?$transactionDetails->volume_packages:'';?>">
													</td>

													<td><input type="text" class="field size1"
														alt="Volume Quantity"
														style="width: 50px; text-align: center"
														id="volume_volume*" name="volume_volume"
														value="<?php echo isset($transactionDetails)?$transactionDetails->volume_volume:'';?>">
													</td>

													<td><input type="text" class="field size1"
														alt="Volume Quantity"
														style="width: 50px; text-align: center" id="volume_qty*"
														name="volume_qty"
														value="<?php echo isset($transactionDetails)?$transactionDetails->volume_qty:'';?>">
													</td>
													<td><select class="field size3" syle="width:75px"
														name="volume_containersize" style="text-align: center"
														id="volume_containersize*" alt="Containerize">
															<option value="">-select-</option>
															<?php
															if(isset($container))
															foreach ($container->result() as $cn)
															{
																echo "<option value='".$cn->id."'    ".((isset($transactionDetails) && $cn->id == $transactionDetails->volume_containersize)?"selected":"").">".$cn->name."</option>";
															}
															?>


													</select>
													</td>
													<td>
												
												</tr>
											</table>
										</td>
									</tr>



									<tr>
										<td height="80" valign="top"><span class="req"></span> <label
											style="text-align: left">Truck Details<span></span> </label>
											<table>
												<tr>
													<th>Company</th>
													<th>Name</th>
													<th>Contact</th>
												</tr>
												<tr>
													<td><input type="text" class="field size1"
														style="width: 150px; text-align: center"
														name="truck_company" id="truck_company*"
														alt="Truck Details - Company"
														value="<?php echo isset($transactionDetails)?$transactionDetails->truck_company:'';?>">
													</td>
													<td><input type="text" class="field size1"
														style="width: 150px; text-align: center" name="truck_name"
														id="truck_name*" alt="Truck Details - Name"
														value="<?php echo isset($transactionDetails)?$transactionDetails->truck_name:'';?>">
													</td>
													<td><input type="text" class="field size1"
														style="width: 130px; text-align: center"
														name="truck_number" id="truck_number*"
														alt="Truck Details - Number"
														value="<?php echo isset($transactionDetails)?$transactionDetails->truck_number:'';?>">
													</td>
												</tr>
											</table>
										</td>
										<td valign="top"><span class="req"></span> <label
											style="text-align: left">Truck<span></span> </label>
											<table>
												<tr>
													<th>Quantity</th>
													<th>Type of Truck</th>
												</tr>
												<tr>
													<td><input type="text" class="field size1"
														style="width: 100px; text-align: center" name="truck_qty"
														id="truck_qty*" alt="Truck Details - Quantity"
														value="<?php echo isset($transactionDetails)?$transactionDetails->truck_qty:'';?>">
													</td>
													<td><?php
													$trucktype =isset($transactionDetails)?$transactionDetails->truck_type:'';
													?> <select class="field size3" name="truck_type"
														style="text-align: center" alt="Truck Details - Quantity"
														id="truck_type*">
															<option value="">--select --</option>
															<option value="4W"
															<?php echo ($trucktype == '4W')?'selected' :''; ?>>4
																Wheeler</option>
															<option value="6W"
															<?php echo ($trucktype == '6W')?'selected' :''; ?>>6
																Wheeler</option>
															<option value="10W"
															<?php echo ($trucktype == '10W')?'selected' :''; ?>>10
																Wheeler</option>
													</select>
													
													<td>
												
												</tr>
											</table>
										</td>
									</tr>





									<tr>
										<td valign="top"><span class="req"></span> <label>Pick Up
												Address <span></span> </label> <textarea class="field size3"
												rows="5" style="width: 90%" name="pickupaddress">
												<?php echo isset($transactionDetails)?$transactionDetails->pickupaddress:'';?>
											</textarea>
										</td>
										<td valign="top"><span class="req"></span> <label>Date/Time of
												Pick Up<span></span> </label>
											<table>
												<tr>
													<td><input type="text" class="field size1"
														style="width: 100px" name="dateofpickup"
														id="dateofpickup*" alt="Date of Pickup"
														value="<?php echo isset($transactionDetails)?$transactionDetails->dateofpickup:'';?>" />
													</td>
													<td><input type="text" class="field size1"
														style="width: 60px" name="timeofpickup" id="timeofpickup*"
														alt="Time of Pickup"
														value="<?php echo isset($transactionDetails)?$transactionDetails->timeofpickup:'';?>" />
													</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td valign="top"><span class="req"></span> <label>Destination
												Point<span></span> </label> <textarea class="field size3"
												rows="5" style="width: 90%" name="deliverypoint"
												id="deliverypoint*" alt="Delivery Point">
												<?php echo isset($transactionDetails)?$transactionDetails->deliverypoint:'';?>
											</textarea>
										</td>
										<td valign="top"><span class="req"></span> <label>On Board
												Date/ETD<span></span> </label>
											<table>
												<tr>
													<td><input type="text" class="field size1"
														style="width: 100px" name="onboarddate" id="onboarddate*"
														alt="On Board Date"
														value="<?php echo isset($transactionDetails)?$transactionDetails->onboarddate:'';?>" />
													</td>
													<td><input type="text" class="field size1"
														style="width: 60px" name="onboardtime"
														value="<?php echo isset($transactionDetails)?$transactionDetails->onboardtime:'';?>" />
													</td>
												</tr>
											</table> <br>
										</td>
									</tr>

									<tr>
										<td valign="top"><span class="req"></span> <label>Updates<span></span>
										</label> <textarea class="field size3" rows="5"
												style="width: 90%" name="intransitlocation"
												id="intransitlocation" alt="In Transit Location">
												<?php echo isset($transactionDetails)?$transactionDetails->intransitlocation:'';?>
											</textarea>
										</td>
										<?php
										if(isset($transactionDetails)){
											?>
										<td valign="top"><label>Date Delivered<span></span> </label>
											<table>
												<tr>
													<td><input type="text" class="field size1 hasDatepicker"
														id="datedelivered" style="width: 100px"
														name="datedelivered" id="datedelivered"
														alt="Date Delivered"
														value="<?php echo isset($transactionDetails)?$transactionDetails->datedelivered:'';?>" />
													</td>
													<td><input type="text" class="field size1"
														style="width: 60px" name="timedelivered"
														value="<?php echo isset($transactionDetails)?$transactionDetails->timedelivered:'';?>" />
													</td>
												</tr>
											</table> <?php
										}
										?></td>
									</tr>





									<?php
									if(isset($transactionDetails)){
										?>
									<tr>
										<td valign="top"><label>Notes</label><br /> <textarea
												class="field size3" rows="5" style="width: 90%" name="notes">
												<?php echo isset($transactionDetails)?$transactionDetails->notes:'';?>
											</textarea>
										</td>
										<td valign="top"></td>
									</tr>
									<tr>
										<td valign="top"><label>Remarks</label><br /> <textarea
												class="field size3" rows="5" style="width: 90%"
												name="remarks">
												<?php echo isset($transactionDetails)?$transactionDetails->remarks:'';?>
											</textarea>
										</td>
										<td valign="top"></td>
									</tr>


									<?php
									}
									?>

								</table>
							</div>

						</div>
						<!-- End Form -->

						<!-- Form Buttons -->
						<div class="buttons">
							<input type="submit" class="button" value="Save Transaction" />
						</div>
						<!-- End Form Buttons -->
					</form>
				</div>
				<!-- End Box -->
				<?php
			}
			?>


			</div>
			<div class="cl">&nbsp;</div>
			<!-- End Content -->

			<!-- Sidebar -->
			<div id="sidebar">


				<!-- End Box -->
			</div>
			<!-- End Sidebar -->

			<div class="cl">&nbsp;</div>
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->



<!-- DIALOG  --->
<div id="displaySearchDialog" title="Search Transaction"
	style="display: none">
	<div class="form">
		<form id="searchTransactionForm"
			action="<?php echo ADMINBASEURL?>transaction" method="post">
			<input type="hidden" name="search" value="search">
			<table width="100%">
				<tr>
					<td><label>DR Number</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="dr_number"></td>
					<td><label>Client Track Number</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="clienttracknumber"></td>
				</tr>
				<tr>
					<td><label>Client First Name</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="firstname"></td>
					<td><label>Client Last Name</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="lastname"></td>
				</tr>
				<tr>
					<td><label>Commodity</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="commodity"></td>
					<td><label>Delivery Point</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="deliverypoint"></td>
				</tr>

			</table>
		</form>
	</div>
</div>


<!-- DIALOG  --->
<div id="displayDownloadDialog" title="Download Transaction Report"
	style="display: none">
	<div class="form">
		<form id="downloadTransactionForm"
			action="<?php echo ADMINBASEURL?>transaction" method="post">
			<input type="hidden" name="download" value="download">
			<table width="100%">
				<tr>
					<td colspan="4"><label>Date</label></td>
				</tr>
				<tr>
					<td><label>From</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="fromDate" id="fromDateDownload"></td>
					<td><label>To</label></td>
					<td><input type="text" class="field size1" style="width: 150px"
						name="toDate" id="toDateDownload"></td>
				</tr>
			</table>
		</form>
	</div>
</div>
